import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/Layout/index.vue'
import { useUserStore } from '@/stores'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({
  showSpinner: false
})
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/login/index.vue'),
      meta: {
        title: '首页'
      }
    },
    {
      path: '/',
      component: Layout,
      redirect: '/home',
      children: [
        {
          path: '/home',
          component: () => import('@/views/Home/index.vue'),
          // 给每个路由设置标题名称
          meta: {
            title: '1'
          }
        },
        {
          path: '/article',
          component: () => import('@/views/Article/index.vue'),
          meta: {
            title: '2'
          }
        },
        {
          path: '/notify',
          component: () => import('@/views/Notify/index.vue'),
          meta: {
            title: '消息中心'
          }
        },
        {
          path: '/user',
          component: () => import('@/views/User/index.vue'),
          meta: {
            title: '我的'
          }
        }
      ]
    }
  ]
})

// // 路由前置守卫
// router.beforeEach((to) => {
//   // 开启进度条
//   NProgress.start()
//   return true
//   // 创建每个页面的网页标题

//   // //创建白名单
//   // const whiteList = ['/login']
//   // // 如果没有token,并且不在白名单中,就跳转到登录页
//   // const store = useUserStore()
//   // if (!store.user?.token && !whiteList.includes(to.path)) return '/login'
// })

// router.beforeEach((to) => {
//   // 修改标题 -  建议放在这里 - 只有走到这里的路由才会修改标题
//   document.title = `${'xxx - ' + to.meta.title}`
//   // 关闭进度条
//   NProgress.done()
// })

export default router
